﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;

namespace Vehicle_Maintenance
{
    class FillUp
    {
        public FillUp() { }
        public string VIN = string.Empty;
        public string Date = string.Empty;
        public string Odom = string.Empty;
        public string CostGal = string.Empty;
        public string Gal = string.Empty;
        public string PayType = string.Empty;
        public string Loc = string.Empty;
        public string GasBrand = string.Empty;
        public string Octane = string.Empty;
        public string Miles = string.Empty;

        public void New(string t_gal)
        {
            using (SqlConnection scConnect = new SqlConnection(Properties.Settings.Default.Auto_Log))
            {
                scConnect.Open();
                SqlCommand scCommand = new SqlCommand();
                scCommand.Connection = scConnect;
                scCommand.CommandType = CommandType.StoredProcedure;
                scCommand.CommandText = "fillups_insert";
                scCommand.Parameters.AddWithValue("@VehicleID", this.VIN);
                scCommand.Parameters.AddWithValue("@DateTime", this.Date);
                scCommand.Parameters.AddWithValue("@Odom", this.Odom);
                scCommand.Parameters.AddWithValue("@Cost_Gal", this.CostGal);
                scCommand.Parameters.AddWithValue("@Gal", this.Gal);
                scCommand.Parameters.AddWithValue("@Pay_Type", this.PayType);
                scCommand.Parameters.AddWithValue("@Loc", this.Loc);
                scCommand.Parameters.AddWithValue("@Gas_Brand", this.GasBrand);
                scCommand.Parameters.AddWithValue("@Octane", this.Octane);
                scCommand.Parameters.AddWithValue("@Miles", this.Miles);
                scCommand.ExecuteNonQuery();
                scConnect.Close();
            }

            using ( SqlConnection scConnect = new SqlConnection( Properties.Settings.Default.Auto_Log ) )
            {
                scConnect.Open();
                SqlCommand scCommand = new SqlCommand();
                scCommand.Connection = scConnect;
                scCommand.CommandType = CommandType.StoredProcedure;
                scCommand.CommandText = "update_odom";
                scCommand.Parameters.AddWithValue( "@VehicleID", this.VIN );
                scCommand.Parameters.AddWithValue( "T_Gal", t_gal);
                scCommand.Parameters.AddWithValue( "@Curr_Odom", this.Odom );
                scCommand.ExecuteNonQuery();
                scConnect.Close();
            }
        }
    }
}
